package org.meruvian.yama.dao;

import javax.swing.JOptionPane;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.meruvian.yama.dao.base.BaseDaoHibernate;
import org.meruvian.yama.entity.User;
import org.springframework.stereotype.Repository;

/**
 * 
 * @author vick
 * 
 */
@Repository
public class UserDao extends BaseDaoHibernate<User> {

	public User getBySecret(String secret) {
		return (User) sessionFactory.getCurrentSession()
				.createCriteria(domainClass)
				.add(Restrictions.eq("secret", secret)).uniqueResult();
	}

	public User getByUserPassword(String username, String password) {
		Criteria criteria = sessionFactory.getCurrentSession()
				.createCriteria(domainClass)
				.add(Restrictions.eq("username", username))
				.add(Restrictions.eq("password", password));

		// String hql = "FROM " + domainClass.getName()
		// + " d WHERE d.username = :user AND d.password = :pass";
		// Query query = sessionFactory.getCurrentSession().createQuery(hql);
		// query.setParameter("user", username);
		// query.setParameter("pass", password);

		return (User) criteria.uniqueResult();
	}
}
